<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="manage/layout :: common_header(~{::title})">
    <title>图集管理-网站后台管理中心</title>
</head>
<body th:replace="manage/layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">

    <div class="sp-wrapper">
        <blockquote class="layui-elem-quote layui-text">
            图集管理
        </blockquote>

        <fieldset class="layui-elem-field">
            <legend>按条件搜索</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane1" method="get" th:action="@{/manage/photo_list}">
                    <div class="layui-form-item">
<!--                        <div class="layui-inline">-->
<!--                            <input type="text" name="title" placeholder="标题" class="layui-input">-->
<!--                        </div>-->

                        <div class="layui-inline">
<!--                            <button type="submit" class="layui-btn layui-btn-normal">搜索</button>-->
                            <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                        </div>

                        <div class="layui-inline">
                            <a class="layui-btn layui-btn-primary" th:href="@{/manage/photo_add}">添加图集</a>
                        </div>
                    </div>

                </form>
            </div>
        </fieldset>


            <table class="layui-table dd-table" lay-even lay-skin="row">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>图集名</th>
                    <th>排序</th>
                    <th>所属公司</th>
                    <th>图片</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td class="center" th:text="${item.id}"></td>
                    <td class="center" th:text="${item.getTitle()}"></td>
                    <td class="center" th:text="${item.getSort()}"></td>
                    <td>
                        <span th:if="${item.companyId != null}" th:text="${T(com.huayi.website.entity.EnumCompany).getName(item.companyId)}"></span>
                    </td>
                    <td>
                        <img th:each="img:${item.images}" th:src="${img}">
                    </td>

                    <td class="center">
                        <a class="layui-btn layui-btn-primary layui-btn-small"
                           th:href="@{/manage/photo_edit(id=${item.getId()})}"><i class="layui-icon"></i>修改</a>
                        <a class="layui-btn layui-btn-primary layui-btn-small delete_data" th:if="${item.id!=1 || item.id!=2 ||item.id!=3 ||item.id!=4}" th:attr="data-id=${item.id}" href="javascript:;">删除</a>
                    </td>
                </tr>
                </tbody>
            </table>

        <div class="layui-box layui-laypage layui-laypage-default">

        </div>
        <div class="layui-box layui-laypage layui-laypage-default pageBox">
            <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
        </div>
        <script type="text/javascript">
            //JavaScript代码区域
            layui.use(['jquery','form','layer'], function () {
               var $$ = layui.jquery;
                var form = layui.form;
                var layer = layui.layer;
                $$(function(){
                    var category = '[[${category}]]';
                    if(category !='' ) {
                        $$("#type").val(category);
                        form.render();
                    }

                    $$(".delete_data").click(function () {
                        if(confirm("删除不可逆，确定要删除吗？")){
                            var productId = $$(this).attr("data-id");
                            // alert(productId);
                            $$.ajax({
                                url: "/manage/photo_delete",
                                type: "POST",
                                dataType: "JSON",
                                contentType: 'application/json',
                                data: JSON.stringify({id:productId}),
                                success: function (res) {
                                    if (res.code == 0) {
                                        alert("删除成功！");
                                        window.location.reload();
                                    } else {
                                        alert(res.msg);
                                    }


                                }
                            })
                        }
                    })
                })
            });
        </script>


    </div>
</div>
</body>
<html>
